package com.bjb.vr.manager.controller;

import com.bjb.vr.common.ao.SysConfigAo;
import com.bjb.vr.common.ao.SysPlatformAo;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.OptCusConfigService;
import com.bjb.vr.common.service.SysConfigService;
import com.bjb.vr.common.vo.OptCusConfigVo;
import com.bjb.vr.common.vo.SysPlatformVo;
import io.jsonwebtoken.lang.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统配置
 *
 * @version 1.0.0
 * @author: HuJingBo
 * @time: 2022/5/7 18:08
 */
@RestController
@RequestMapping("/api/manager/v1")
public class SystemController {

    @Resource
    private SysConfigService sysConfigService;

    @Resource
    private OptCusConfigService optCusConfigService;

    /**
     * 查询系统设置
     */
    @PostMapping("/querySystemConfig")
    public BaseResult querySystemConfig(@RequestBody SysConfigAo sysConfigAo) {
        return CommonResult.Ok().setResult(sysConfigService.querySystemConfig(sysConfigAo));
    }

    /**
     * 更新系统配置
     *
     * @param sysConfigAo
     * @return
     */
    @PostMapping("/updateSystemConfig")
    public BaseResult updateSystemConfig(@RequestBody SysConfigAo sysConfigAo) {
        Assert.notNull(sysConfigAo.getId(), "ID不能为空");
        boolean success = sysConfigService.updateSystemConfig(sysConfigAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_UPDATE);
        }
        return CommonResult.Ok();
    }

    /**
     * 查询当前租户的平台版本
     *
     * @return
     */
    @PostMapping("/queryPlatform")
    public BaseResult queryPlatform() {
        SysPlatformVo sysPlatformVo = optCusConfigService.queryPlatform();
        return CommonResult.Ok().setResult(sysPlatformVo);
    }

    /**
     * 选择当前租户的平台版本
     *
     * @return
     */
    @PostMapping("/choicePlatform")
    public BaseResult choicePlatform(@RequestBody SysPlatformAo sysPlatformAo) {
        Assert.notNull(sysPlatformAo.getPlatform(), "平台版本不能为空");
        boolean success = optCusConfigService.choicePlatform(sysPlatformAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_ADD);
        }
        return CommonResult.Ok();
    }
}
